import { reactive, computed } from "vue";
import type { FormRules } from "element-plus";
import { FormDataProps } from "./types";
import { i18n } from '@/i18n';

/** 自定义表单规则校验 */
export const rules = computed(() => {
  const i18nObj = i18n.global;
  return reactive(<FormRules>{
    name: [{ required: true, message: i18nObj.t('sys.rolePage.form.rules.nameRequired'), trigger: "blur" }],
    code: [{ required: true, message: i18nObj.t('sys.rolePage.form.rules.codeRequired'), trigger: "blur" }]
  });
});

export const initValues = (row?: FormDataProps): FormDataProps => {
  return {
    name: row?.name ?? "",
    code: row?.code ?? ""
  };
};
